package com.itfreer.print.toPdf;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import com.itextpdf.text.DocumentException;
import com.itfreer.print.toPdf.PptToPdf;

import org.apache.poi.EncryptedDocumentException;
import org.springframework.stereotype.Component;

/**
 * 定义ppt转换为pdf
 */
@Component
public class PptToPdfImp implements PptToPdf {

	/**
	 * ppt转换为pdf
	 * @param pptFile
	 * @param pdfFile
	 * @throws EncryptedDocumentException
	 * @throws IOException
	 * @throws DocumentException
	 */
	public void toPdf(InputStream pptFile, OutputStream pdfFile) 
			throws EncryptedDocumentException, IOException, DocumentException {
		PptToImageImp image = new PptToImageImp();
		List<ByteArrayOutputStream> imageList = image.toImages(pptFile);
		
		List<InputStream> images = new ArrayList<InputStream>();
		for(ByteArrayOutputStream i : imageList){
			InputStream in = new ByteArrayInputStream(i.toByteArray());
			images.add(in);
		}
		
		ImageToPdfImp toPdf = new ImageToPdfImp();
		toPdf.toPdf(images, pdfFile);
	}
}
